<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
        .box{
            margin: 20px;
            padding: 10px;
            border: 1px solid orange;
        }
        .box span{
            display: inline-block;
            background: #666;
            color: #fff;
            padding: 8px;
            margin: 10px;
            border-radius: 5px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <!-- 定义挂载点 -->
    <div id="app">
        <h3>网易云音乐</h3>
        <input type="text" v-model="kw">
        <div class="box">
            <div class="hot">
                <span v-for="item in hots" :key="item" @click="kw=item">{{item}}</span>
            </div>
        </div>
    </div>

    <script>
        new Vue({
            //挂载点
            el:"#app",
            //数据
            data:{
                kw:"",
                hots:["黑月光","玄鸟","薛之谦","张杰"]
            },
            //方法
            methods:{},
            watch:{
                //使用场景：搜索，数据变了，需要做开销比较大的操作  ajax
                kw(){
                    console.log("搜索变了，发起ajax请求：" + this.kw);
                }
            }
        })
    </script>
</body>
</html>